package com.cy.pj.sys.service.impl;

import com.cy.pj.common.pojo.Node;
import com.cy.pj.sys.pojo.SysMenu;
import com.cy.pj.sys.dao.SysMenuDao;
import com.cy.pj.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**菜单业务管理*/
@Transactional(readOnly = false,rollbackFor = Throwable.class,isolation = Isolation.READ_COMMITTED)
@Service
public class SysMenuServiceImpl implements SysMenuService {
    @Autowired
    private SysMenuDao sysMenuDao;

    /**
     * 查询所有菜单。
     * @return
     */
    @Transactional(readOnly = true)
    @Override
    public List<SysMenu> findMenus() {
        return sysMenuDao.selectMenus();
    }

    @Override
    public List<Node> findMenuTreeNodes() {
        return sysMenuDao.selectMenuTreeNodes();
    }
    @Override
    public int saveMenu(SysMenu menu) {
        return sysMenuDao.insertMenu(menu);
    }

    @Transactional(readOnly = true)
    @Override
    public SysMenu findById(Integer id) {
        return sysMenuDao.selectById(id);
    }
    /**
     * 更新菜单信息
     * @param menu
     * @return
     */
    @Override
    public int updateMenu(SysMenu menu) {
        if(menu.getId()==null){
            return sysMenuDao.insertMenu(menu);
        }else{
            return sysMenuDao.updateMenu(menu);
        }
    }
}
